import request from '@/utils/request'

// Mock数据
const mockShipmentList = [
  {
    shipmentId: 1,
    shipmentCode: 'YD202412250001',
    shipmentStatus: '2', // 运输中
    createTime: '2024-12-25 09:30:00',
    updateTime: '2024-12-25 14:20:00',
    
    // 发货信息
    senderId: 1,
    senderName: '北京物流发货中心',
    senderContactName: '张经理',
    senderContactPhone: '13800138001',
    senderProvince: '北京市',
    senderCity: '北京市',
    senderDistrict: '朝阳区',
    senderAddress: '北京市朝阳区建国路88号现代城A座15层',
    senderLongitude: 116.4074,
    senderLatitude: 39.9042,
    
    // 收货信息
    receiverId: 1,
    receiverName: '上海贸易收货公司',
    receiverContactName: '李总监',
    receiverContactPhone: '13900139001',
    receiverProvince: '上海市',
    receiverCity: '上海市',
    receiverDistrict: '浦东新区',
    receiverAddress: '上海市浦东新区陆家嘴环路1000号恒生银行大厦20层',
    receiverLongitude: 121.4737,
    receiverLatitude: 31.2304,
    
    // 货物信息
    goodsName: '高端电子设备',
    goodsType: '5', // 贵重物品
    goodsWeight: 50.5,
    goodsVolume: 2.3,
    
    // 运输信息
    transportMode: '4', // 航空运输
    estimatedShipDate: '2024-12-25',
    estimatedArrivalDate: '2024-12-26',
    freight: 1200.00,
    paymentMethod: '1', // 寄付
    
    // 备注
    remark: '贵重物品，请小心轻放，确保包装完好'
  },
  {
    shipmentId: 2,
    shipmentCode: 'YD202412250002',
    shipmentStatus: '3', // 已签收
    createTime: '2024-12-24 14:15:00',
    updateTime: '2024-12-25 10:45:00',
    
    // 发货信息
    senderId: 2,
    senderName: '广州服装批发中心',
    senderContactName: '王主管',
    senderContactPhone: '13700137002',
    senderProvince: '广东省',
    senderCity: '广州市',
    senderDistrict: '白云区',
    senderAddress: '广州市白云区白云大道北1号服装城B区3楼',
    senderLongitude: 113.2644,
    senderLatitude: 23.1291,
    
    // 收货信息
    receiverId: 2,
    receiverName: '深圳时尚零售店',
    receiverContactName: '陈店长',
    receiverContactPhone: '13600136002',
    receiverProvince: '广东省',
    receiverCity: '深圳市',
    receiverDistrict: '南山区',
    receiverAddress: '深圳市南山区科技园南区深南大道9988号',
    receiverLongitude: 113.9308,
    receiverLatitude: 22.5329,
    
    // 货物信息
    goodsName: '春季时装',
    goodsType: '1', // 普通货物
    goodsWeight: 25.8,
    goodsVolume: 1.5,
    
    // 运输信息
    transportMode: '1', // 公路运输
    estimatedShipDate: '2024-12-24',
    estimatedArrivalDate: '2024-12-25',
    freight: 350.00,
    paymentMethod: '2', // 到付
    
    // 备注
    remark: '季节性商品，请尽快配送'
  },
  {
    shipmentId: 3,
    shipmentCode: 'YD202412250003',
    shipmentStatus: '1', // 待发货
    createTime: '2024-12-25 16:20:00',
    updateTime: '2024-12-25 16:20:00',
    
    // 发货信息
    senderId: 3,
    senderName: '天津化工原料公司',
    senderContactName: '刘工程师',
    senderContactPhone: '13500135003',
    senderProvince: '天津市',
    senderCity: '天津市',
    senderDistrict: '滨海新区',
    senderAddress: '天津市滨海新区开发区第三大街158号化工园区',
    senderLongitude: 117.2008,
    senderLatitude: 39.1042,
    
    // 收货信息
    receiverId: 3,
    receiverName: '青岛制造工厂',
    receiverContactName: '赵厂长',
    receiverContactPhone: '13400134003',
    receiverProvince: '山东省',
    receiverCity: '青岛市',
    receiverDistrict: '黄岛区',
    receiverAddress: '青岛市黄岛区长江路2号工业园区A区',
    receiverLongitude: 120.3826,
    receiverLatitude: 36.0671,
    
    // 货物信息
    goodsName: '工业化学原料',
    goodsType: '4', // 危险品
    goodsWeight: 120.0,
    goodsVolume: 5.8,
    
    // 运输信息
    transportMode: '1', // 公路运输
    estimatedShipDate: '2024-12-26',
    estimatedArrivalDate: '2024-12-27',
    freight: 800.00,
    paymentMethod: '1', // 寄付
    
    // 备注
    remark: '危险品运输，需要专业资质车辆和司机，严格按照安全规范操作'
  }
]

// 查询运单列表
export function listShipment(query) {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({
        code: 200,
        msg: '操作成功',
        rows: mockShipmentList,
        total: mockShipmentList.length
      })
    }, 500)
  })
}

// 查询运单详细
export function getShipment(shipmentId) {
  return new Promise((resolve) => {
    setTimeout(() => {
      const shipment = mockShipmentList.find(item => item.shipmentId == shipmentId) || mockShipmentList[0]
      resolve({
        code: 200,
        msg: '操作成功',
        data: shipment
      })
    }, 300)
  })
}

// 新增运单
export function addShipment(data) {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({
        code: 200,
        msg: '新增成功'
      })
    }, 800)
  })
}

// 修改运单
export function updateShipment(data) {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({
        code: 200,
        msg: '修改成功'
      })
    }, 800)
  })
}

// 删除运单
export function delShipment(shipmentId) {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({
        code: 200,
        msg: '删除成功'
      })
    }, 500)
  })
}

// 导出运单
export function exportShipment(query) {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({
        code: 200,
        msg: '导出成功'
      })
    }, 1000)
  })
}

// 获取运单历史记录
export function getShipmentHistory(query) {
  const mockHistory = [
    {
      id: 1,
      operation: '创建运单',
      operator: '张三',
      operateTime: '2024-01-15 10:30:00',
      remark: '运单创建成功'
    },
    {
      id: 2,
      operation: '状态更新',
      operator: '李四',
      operateTime: '2024-01-15 14:20:00',
      remark: '运单状态更新为运输中'
    }
  ]
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({
        code: 200,
        msg: '操作成功',
        rows: mockHistory,
        total: mockHistory.length
      })
    }, 400)
  })
}

// 获取运单轨迹信息
export function getShipmentTrack(query) {
  const mockTrack = [
    {
      id: 1,
      location: '北京仓库',
      status: '已发货',
      time: '2024-01-15 10:30:00',
      description: '货物从北京仓库发出'
    },
    {
      id: 2,
      location: '天津中转站',
      status: '运输中',
      time: '2024-01-15 14:20:00',
      description: '货物到达天津中转站'
    }
  ]
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({
        code: 200,
        msg: '操作成功',
        rows: mockTrack,
        total: mockTrack.length
      })
    }, 400)
  })
}